<template>
  <div class="page-container">
    <div class="svg-list">
      <div
        class="svg"
        v-for="(item, index) in svg"
        :key="index"
        @click="copy(item.name)"
      >
        <svg-icon class="svg-icon" :icon="item.name" />
      </div>
      <div class="svg-upload">上传</div>
    </div>
  </div>
</template>

<script>
import GetSvgIcon from "@/icons";
export default {
  computed: {
    svg() {
      return GetSvgIcon();
    },
  },
  methods: {
    copy(name) {
      const svg = `<svg-icon icon="${name}" />`;
      console.log(svg);
      this.$copyText(svg).then((res) => {
        this.$message({
          message: `复制成功: ${svg}`,
          type: "success",
        });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.svg-list {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, 100px);
  grid-gap: 8px;
  grid-auto-rows: 100px;
  justify-content: space-between;

  .svg-upload {
    width: 100px;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    box-sizing: border-box;
    border: 1px dashed #d9d9d9;
    color: #ddd;

    &:hover {
      border-color: #409eff;
      color: #409eff;
    }
  }

  .svg {
    width: 100px;
    height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    transition: all 0.58s ease;
    background: #eee;

    &:hover {
      background: #ddd;
      cursor: pointer;
    }

    & span {
      font-size: 12px;
      margin: 8px auto 0;
    }

    .svg-icon {
      width: 40px;
      height: 40px;
    }
  }
}
</style>